package com.kingyea.mobilepolice.apimanage.accesscontrol.controller;

import com.kingyea.mobilepolice.apimanage.accesscontrol.bean.CustomController;
import com.kingyea.mobilepolice.apimanage.accesscontrol.service.CustomControllerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author chenjw
 * @version v1.0.0
 * @description CustomController 控制层
 * @date Created in 2018-04-03 15:32:08
 */
@RequestMapping(value = "/customController")
@RestController
public class CustomControllerController {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomControllerController.class);

    @Autowired
    private CustomControllerService customControllerService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public Object list() throws Exception {
        return customControllerService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Object detail(@PathVariable Integer id) throws Exception {
        return customControllerService.getById(id);
    }

    /**
     * 创建
     *
     * @param customController
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody CustomController customController) throws Exception {
        return customControllerService.save(customController);
    }

    /**
     * 更新
     *
     * @param customController
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public Object update(@RequestBody CustomController customController) throws Exception {
        return customControllerService.update(customController);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Object delete(@PathVariable Integer id) throws Exception {
        return customControllerService.deleteById(id);
    }

    @RequestMapping(value = "/searchByCondition", method = RequestMethod.POST)
    public Object searchByCondition(@RequestBody Map<String, Object> map) throws Exception {

        return customControllerService.searchByCondition(map);
    }

    @RequestMapping(value = "/getInfoBySerAndReqId", method = RequestMethod.POST)
    public Object InfoBySerAndReqId(@RequestBody Map<String, Object> map) throws Exception {
        Integer sid = Integer.parseInt(map.get("serviceId").toString());
        Integer rid = Integer.parseInt(map.get("requesterId").toString());
        CustomController cct = customControllerService.getByParam(map);
        return cct;
    }

    @RequestMapping(value = "/addCusAccInfo", method = RequestMethod.POST)
    public Object addAccinfo(@RequestBody CustomController cusController) throws Exception {
        customControllerService.addOrSaveACCInfo(cusController);
        return "ss";

    }
}
